package com.scuec.groupfive.Controller;

import com.github.pagehelper.PageInfo;
import com.scuec.groupfive.entity.UserInfo;
import com.scuec.groupfive.service.UserService_zm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController_zm {

    @Autowired
    private UserService_zm userService;

    // 1. 获取所有用户列表（不分页）
    //http://localhost:8080/api/user/list
    @CrossOrigin
    @GetMapping("/list")
    public List<UserInfo> getUserList() {
        return userService.getUserList();
    }

    // 2. 根据ID查询单个用户
    // 访问地址：http://localhost:8080/api/user/find?id=1
    @GetMapping("/find")
    public UserInfo getUserById(@RequestParam Integer id) {
        return userService.getUserById(id);
    }

    // 3. 分页查询用户列表（带关键字查询）
    // 访问地址：http://localhost:8080/api/user/pages?pageNum=1&pageSize=10
    // 带关键字查询：http://localhost:8080/api/user/pages?pageNum=1&pageSize=10&keyword=admin
    @GetMapping("/pages")
    public PageInfo<UserInfo> getUserPages(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String keyword) {
        return userService.getUserPages(pageNum, pageSize, keyword);
    }
}